<template>
  <!-- 个人考核维护 -->
  <base-breadcrumb :title="$route.meta.title">
    <!-- 搜索 -->
    <searchData :searchData="searchArr" @search="search"></searchData>
    <!-- 表格 -->
    <a-card :bordered="false">
      <!-- <title-name title="安全责任指标考核记录" /> -->

      <!-- 表格 -->
      <list-table
        ref="table"
        :page-keys="['pageNo', 'pageSize', 'totalSize']"
        tableLayout="fixed"
        size="default"
        rowKey="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
      >
        <template slot="action" slot-scope="text, record">
          <MoreButton>
            <a :disabled="record.type*1===0" @click="handleManage(0, record)" v-btnPermission="'hse_016_loo_07'">查看</a>
            <span v-if="record.auditStatus != 'SUBMITTED' && record.auditStatus != 'PAST'" v-btnPermission="'hse_016_edi_05'">
              <a-divider type="vertical" />
              <a :disabled="record.type*1===0" @click="handleManage(1, record)">编辑</a>
            </span>
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格

import BasePage from '@/views/basePage' // 基础配置
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import api from '@/api/safetySupervision/base/inspectionTemplate.js'
import MoreButton from '@/components/MoreButton'
const searchArr = [
  // 搜索框
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  // {
  //   name: '所属分公司',
  //   valueKey: 'branchCompanyId',
  //   type: SelectSubCompany
  // },
  // {
  //   name: '所属项目',
  //   keyValue: 'branchCompanyId',
  //   valueKey: 'projectId',
  //   type: SelectProject
  // },
  {
    name: '考核月份',
    type: 'month',
    value: 'checkMonth',
    attrs: {
      valueFormat: 'YYYY-MM'
    }
  },

  {
    name: '姓名',
    type: 'input',
    value: 'checkName'
  },
  {
    name: '等级',
    value: 'level',
    type: 'select',
    data: [
      {
        value: 'A',
        label: 'A'
      },
      {
        value: 'B',
        label: 'B'
      },
      {
        value: 'C',
        label: 'C'
      }
    ]
  }
]
const columns = [
  {
    title: '考核月份',
    dataIndex: 'checkMonth',
    width:100,
  },

  {
    title: '姓名',
    dataIndex: 'checkName',
    width:100,
    ellipsis: true
  },
  {
    title: '岗位',
    dataIndex: 'checkPost',
    width:100, 
    ellipsis: true
  },
  {
    title: '部门',
    dataIndex: 'checkDept',
    width:100, 
    ellipsis: true
  },
  {
    title: '得分',
    dataIndex: 'realScore',
    width:80,
  },
  {
    title: '等级',
    dataIndex: 'level',
    width:80,
  },
  {
    title: '所属分公司',
    dataIndex: 'branchCompanyName',
    width:150,
    ellipsis: true
  },
  {
    title: '所属项目',
    dataIndex: 'projectName',
    width:380,
    ellipsis: true
  },

  {
    title: '操作',
    dataIndex: 'action',
    width:180,
    align: 'center',
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    STable,
    MoreButton
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {}, // 查询参数

      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
        console.log(requestParameters)
        return api.listRecord(requestParameters).then((res) => {
          return res
        })
      },
      removeApi: { remove: api.delPerson } // api
    }
  },
  methods: {
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    // 操作栏
    handleManage(type, record) {
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: 'updateInspectionRecords',
        query
      })
    }
  }
}
</script>
